﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;

namespace AutoPartsSearch.Web.HtmlHelpers
{
    public static class MenuHelper
    {
        public static MvcHtmlString MenuItem(this HtmlHelper helper, string linkText, string action, string controller, string currentPageClass, string additionalClass = "")
        {
            var routeData = helper.ViewContext.RouteData;
            var routeController = routeData.GetRequiredString("controller");
            var routeAction = routeData.GetRequiredString("action");
            if(string.Equals(action, routeAction, StringComparison.OrdinalIgnoreCase)
                && string.Equals(controller, routeController, StringComparison.OrdinalIgnoreCase))
            {
                return helper.ActionLink(linkText, action, controller, null, new { @class = additionalClass + " " + currentPageClass });
            }
            return helper.ActionLink(linkText, action, controller, null, new { @class = additionalClass});
        }
    }
}